package cn.modificator.relationtree

import android.animation.AnimatorInflater
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v4.view.MenuItemCompat
import android.text.InputType
import android.view.Gravity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.RadioGroup
import android.support.v7.widget.Toolbar
import cn.modificator.relationtree.utils.kindLayout
import org.jetbrains.anko.*
import org.jetbrains.anko.appcompat.v7.toolbar

class CreateNewContentActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        CreateNewUI().setContentView(this)
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menu?.let {menu->
            menu.add(0,1,0,"保存").setIcon(R.drawable.ic_save_black_24dp).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
        }
        return super.onCreateOptionsMenu(menu)
    }
    class CreateNewUI : AnkoComponent<CreateNewContentActivity> {

        lateinit var toolbar: Toolbar

        override fun createView(ui: AnkoContext<CreateNewContentActivity>): View = with(ui) {
            verticalLayout {
                toolbar =toolbar {
                    title = "创建客户信息"
                    backgroundColor = 0xffdddddd.toInt()
                    isActivated = true
                    stateListAnimator = AnimatorInflater.loadStateListAnimator(ui.ctx, R.animator.toolbar_raise)
                }
                ui.owner.setSupportActionBar(toolbar)
                scrollView {
                    verticalLayout {
                        kindLayout {
                            title = "基本信息"
                            primaryColor = 0xFF0FE3FA.toInt()
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "名字" }
                                editText().lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "性别" }
                                radioGroup {
                                    orientation = RadioGroup.HORIZONTAL
                                    radioButton {
                                        text = "男"
                                        isChecked = true
                                    }
                                    radioButton { text = "女" }
                                }.lparams {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "联系电话" }
                                editText {
                                    inputType = InputType.TYPE_CLASS_PHONE
                                }.lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "家庭住址" }
                                editText().lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "个人爱好" }
                                editText().lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "所属行业" }
                                editText().lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "订单编号" }
                                editText {
                                    inputType = InputType.TYPE_CLASS_NUMBER
                                }.lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "意向类型" }
                                spinner {
                                    adapter = ArrayAdapter<String>(ui.ctx, android.R.layout.simple_spinner_dropdown_item, arrayOf("O", "H", "A", "B", "C"))
                                    dropDownWidth = dip(70)
                                }.lparams(wrapContent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                        }

                        kindLayout {
                            title = "需求评估"
                            primaryColor = 0xFF0FE3FA.toInt()

                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "购车用途" }
                                editText().lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "对比车型" }
                                editText().lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "购车使用者" }
                                editText().lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "购车意向周期" }
                                editText().lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "意向车型" }
                                editText().lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "购车预算" }
                                editText().lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "其他" }
                                editText().lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                        }

                        kindLayout {
                            title = "详细"
                            primaryColor = 0xffff0000.toInt()

                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "客户来源" }
                                spinner {
                                    adapter = ArrayAdapter<String>(ui.ctx,
                                            android.R.layout.simple_spinner_dropdown_item,
                                            arrayOf("爱卡", "易车", "太平洋", "自然到店", "车展",
                                                    "定巡展", "58二手车", "朋友介绍"))
                                    dropDownWidth = dip(170)
                                }.lparams(wrapContent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "首次接待结果" }
                                editText {
                                    inputType = InputType.TYPE_TEXT_FLAG_MULTI_LINE
                                }.lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "后续措施" }
                                editText {
                                    inputType = InputType.TYPE_TEXT_FLAG_MULTI_LINE
                                }.lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            view { backgroundColor=0x44000000.toInt() }.lparams(matchParent,dip(0.7f))
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView("客户跟踪").lparams {
                                    weight = 1.toFloat()
                                }
                                imageView(R.drawable.ic_keyboard_arrow_right) {
                                    scaleType = ImageView.ScaleType.CENTER_INSIDE
                                    padding = dip(12)
                                }.lparams(dip(45), dip(45))
                            }.lparams(matchParent, dip(45))
                            view { backgroundColor=0x44000000.toInt() }.lparams(matchParent,dip(0.7f))
                        }
                        kindLayout {
                            title = "跟踪结果"
                            primaryColor = 0xffff0000.toInt()

                            spinner {
                                adapter = ArrayAdapter<String>(ui.ctx,
                                        android.R.layout.simple_spinner_dropdown_item,
                                        arrayOf("成交--购车", "流失--购买其他品牌产品", "购车计划取消"))
//                                dropDownWidth = dip(170)
                            }.lparams(wrapContent, wrapContent) {
                                leftMargin = dip(15)
                            }
                        }
                        kindLayout {
                            title = "成交车辆信息"
                            primaryColor = 0xffff0000.toInt()
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "车型代号" }
                                editText {
                                }.lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "车身号码" }
                                editText {
                                }.lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "发动机号" }
                                editText {
                                }.lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "颜色" }
                                editText {
                                }.lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView { text = "出厂" }
                                editText {
                                }.lparams(matchParent, wrapContent) {
                                    leftMargin = dip(15)
                                }
                            }
                        }
                        kindLayout {
                            title = "结果分析"
                            primaryColor = 0xffff0000.toInt()
                            editText {
                            }
                        }

                        linearLayout {
                            gravity = Gravity.CENTER_VERTICAL
                            textView { text = "销售顾问" }
                            editText {
                            }.lparams(matchParent, wrapContent) {
                                leftMargin = dip(15)
                            }
                        }
                        linearLayout {
                            gravity = Gravity.CENTER_VERTICAL
                            textView { text = "销售经理" }
                            editText {
                            }.lparams(matchParent, wrapContent) {
                                leftMargin = dip(15)
                            }
                        }
                    }
                }
            }
        }

    }
}
